//
//  IMLoginStateUtil.m
//  IMChezhil
//
//  Created by zhangliucheng on 15/7/23.
//  Copyright (c) 2015年 CheZhil. All rights reserved.
//

#import "IMLoginStateUtil.h"

@implementation IMLoginStateUtil

+ (NSString *)getUin {
    NSString *uin = @"游客";
    IMLoginMessage *loginMessage = [IMLoginStateUtil restoreLoginMessage];
    if (Nil != loginMessage) {
        uin = loginMessage.uin;
    }
    return uin;
}

+ (IMLoginMessage *)restoreLoginMessage {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *uin = [defaults objectForKey:@"uin"];
    if (!uin || uin.length == 0) {
        return Nil;
    }
    NSString *token = [defaults objectForKey:@"token"];
    NSString *clientId = [defaults objectForKey:@"clientId"];
    IMLoginMessage *loginMessage = [[IMLoginMessage alloc] initWithUin:uin token:token clientId:clientId];
    return loginMessage;
}

+ (void)saveLoginMessage:(IMLoginMessage *)loginMessage {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:loginMessage.uin forKey:@"uin"];
    [defaults setObject:loginMessage.token forKey:@"token"];
    [defaults setObject:loginMessage.clientId forKey:@"clientId"];
}

+ (void)clearLoginMessage {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults removeObjectForKey:@"uin"];
    [defaults removeObjectForKey:@"token"];
    [defaults removeObjectForKey:@"clientId"];
}

@end
